﻿
using System;
using System.Collections.Generic;
using System.Text;

namespace LxCFD
{
    public partial class MonitorCenter : IReset
    {
        public MonitorCenter()
        {
            ResidualMonitors = new List<ResidualMonitor>();
            void create(ref ResidualMonitor item, string name)
            {
                item = new ResidualMonitor() { name = name, IsKeepData = true };
                ResidualMonitors.Add(item);
            }
            create(ref Continuity, "连续性");
            create(ref Vel_U, "动量U");
            create(ref Vel_V, "动量V");
            create(ref Vel_W, "动量W");
            create(ref Temperature, "温度");
            create(ref Turb_k, "湍动能");
            create(ref Turb_omega, "比耗散率");
        }
        public ResidualMonitor Continuity;
        public ResidualMonitor Vel_U;
        public ResidualMonitor Vel_V;
        public ResidualMonitor Vel_W;
        public ResidualMonitor Temperature;
        public ResidualMonitor Turb_k;
        public ResidualMonitor Turb_omega;
        public List<ResidualMonitor> ResidualMonitors;
        public List<MonitorBase> UserMonitors = new List<MonitorBase>();
        public void Monitor_Steady()
        {
            StringBuilder resultReport = new StringBuilder();
            resultReport.Append("|step:");
            resultReport.Append(AppRes.StepsCenter.SteadyStep.StepsCount);
            resultReport.Append("|");
            foreach (var s in ResidualMonitors)
            {
                s.RunMonitor();
                if (s.IsCurrentExist)
                {
                    resultReport.Append(s.name);
                    resultReport.Append(":");
                    resultReport.Append(s.CurrentResult.ToString("N6"));
                    resultReport.Append("|");
                }
            }
            LxConsole.Calc(resultReport.ToString());
            TestMonitor testMonitor = new TestMonitor();
            testMonitor.RunMonitor();
        }
        public void Monitor_Transient()
        {
            LxConsole.Info(string.Format($"===time step: {AppRes.StepsCenter.TransientStep.StepsCount} result time:{AppRes.SolveCenter.TransientTime.ResultTime}==="));
        }
        public void Reset(ResetTypes clearType)
        {
            foreach (var s in ResidualMonitors)
            {
                s.Reset(clearType);
            }
            foreach (var s in UserMonitors)
            {
                s.Reset(clearType);
            }
        }
    }
}
